﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using iFinance.Modules.Authorization.ViewModels;

namespace iFinance.Modules.Authorization
{
    public partial class LoginView : UserControl
    {
        public LoginView()
        {
            InitializeComponent();
            this.hbtnRegister.Click += new RoutedEventHandler(hbtnRegister_Click);
            this.hbtnForgetPwd.Click += new RoutedEventHandler(hbtnForgetPwd_Click);
            this.txtUserID.Focus();
            this.txtUserID.TextChanged += new TextChangedEventHandler(txtUserID_TextChanged);
            this.pwd.PasswordChanged += new RoutedEventHandler(pwd_PasswordChanged);
        }

        void pwd_PasswordChanged(object sender, RoutedEventArgs e)
        {
            this.pwd.GetBindingExpression(PasswordBox.PasswordProperty).UpdateSource();
        }

        void txtUserID_TextChanged(object sender, TextChangedEventArgs e)
        {
            this.txtUserID.GetBindingExpression(TextBox.TextProperty).UpdateSource();
        }

        void hbtnForgetPwd_Click(object sender, RoutedEventArgs e)
        {
            var forgetPwdView = new ForgetPwdView();
            forgetPwdView.Show();
        }

        void hbtnRegister_Click(object sender, RoutedEventArgs e)
        {
            RegisterViewModel viewModel = new RegisterViewModel();
            var regView = new RegisterView();
            regView.DataContext = viewModel;
            regView.Show();
            regView.Closed += (x, y) =>
                {
                    this.txtUserID.Text = viewModel.UserID;
                    this.pwd.Password = viewModel.Password;
                };
        }
    }
}
